1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10
11 namespace SoftQuanLyNhaHang.Views
12 {
13 public partial class uctThongTinSanPham : UserControl
14 {
15 public uctThongTinSanPham()
16 {
17 InitializeComponent();
18 }
19
20 //khởi tạo gọi trong menuscript
21 public static uctThongTinSanPham uctTTSP = new uctThongTinSanPham();
22
23 int _idThongTinSanPham = 0;
24 string _maSanPham = "";
25 string _tenSanPham = "";
26 int _nhaCungCapId = 0;
27
28 string _tenNhaCungCap = "";
29 int _donViTinhId = 0;
30 string _tenDonViTinh = "";
31 string _ghiChu= "";
32 DateTime _ngayTao = DateTime.Now;
33 int _trangThai = 1;
34 int i = 0;
35 DataTable dt = new DataTable();
36
37 private void btnThemMoi_Click(object sender, EventArgs e)
38 {
39 _maSanPham = txtMaSanPham.Text.Trim();
40 _tenSanPham = txtTenSanPham.Text.Trim();
41
42 _trangThai = 1;
43 _ngayTao = DateTime.Now;
44
45 _ghiChu = txtGhiChu.Text.Trim();
46
47
48 i = 0;
49
50 i = Controllers.ThongTinSanPhamCtrl.InsertThongTinSanPham(_idThongTinSanPham, _maSanPham, _tenSanPham, _nhaCungCapId, _tenNhaCungCap, _donViTinhId, _tenDonViTinh, _ghiChu, _ngayTao, _trangThai);
51 if (i > 0)
52 {
53 MessageBox.Show("Thêm mới thành công");
54 }
55 }
56
57 private void txtMaSanPham_Enter(object sender, EventArgs e)
58 {
59 //MessageBox.Show(txtMaSanPham.Text);
60 }
61
62 private void txtMaSanPham_KeyDown(object sender, KeyEventArgs e)
63 {
64 if (e.KeyCode == Keys.Enter)
65 {
66 //MessageBox.Show(txtMaSanPham.Text);
67 //Kiểm tra mã sản phẩm có tồn tại trong hệ thông hay không
68 i = 0;
69 dt = Controllers.ThongTinSanPhamCtrl.FillDataSet_ThongTinSanPhamByMaSanPham(txtMaSanPham.Text.Trim()).Tables[0];
70
71 if(dt.Rows.Count > 0)
72 {
73 //Tồn tại mã sản phẩm trong hệ thống
74 btnThemMoi.Enabled = false;
75 }
76 else
77 {
78 //Hiển thị nút thêm mới
79 btnThemMoi.Enabled = true;
80
81 }
82
83 }
84 }
85 }
86 }